/**
 * Created by Administrator on 2017/3/17 0017.
 */
Page2={
    Create:function(){
        var page={};
        var whole=new PIXI.DisplayObjectContainer();
        var bigWhole=new PIXI.DisplayObjectContainer();
        var wholeMask=new PIXI.Graphics();
        wholeMask.beginFill(0x000000,1);
        wholeMask.drawRect(0,0,900,1136);
        wholeMask.scale.set(1,0);
        wholeMask.rotation=Math.PI/180*-9;


        var delayTime=3 ;
        // var delayTime=0 ;

        var title1=PSP("page2_12");
        var title2=PSP("page2_17");
        var title3=PSP("page2_29");
        var word=PSP("page2_4");
        var wordBG=PSP("page2_3");
        var sir=PSP("page2_11");
        var pink=PSP("page2_5");
        var bottom1=PSP("page2_7");
        var bottom2=PSP("page2_9");
        var bg=PSP("page2_10");
        var bgUp=PSP("page2_33");
        var bgDown=PSP("page2_32");

        var bgUp2=PSP("page2_34");
        var bgUp3=PSP("page2_35");




        bgDown.y=1136-280;
        // bg.x=bg.width/2;bg.y=bg.height/2;

        var bgUpMask=PSP("page2_5");
        whole.addChild(bgUpMask);
        bgUp.mask=bgUpMask;

        //第二,三页
        var sir2=PSP("page2_15");
        var sir3=PSP("page2_16");

        var word1=PSP("page2_13");
        var word2=PSP("page2_14");

        var line1=new PIXI.Graphics();
        line1.lineStyle(1,0xffffff,1);
        line1.moveTo(320,290);
        line1.lineTo(420,290);

        var line2=new PIXI.Graphics();
        line2.lineStyle(1,0xffffff,1);
        line2.moveTo(320,435);
        line2.lineTo(420,435);

        //**********************
        //**********************
        //**********************
        //**********************

        var speedLine1=PSP("page2_21");
        speedLine1.x=10;speedLine1.y=774;
        TweenMax.to(speedLine1,1,{x:380,y:315,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine2=PSP("page2_22");
        speedLine2.x=4;speedLine2.y=904;
        TweenMax.to(speedLine2,1,{delay:0.3,x:394,y:404,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine3=PSP("page2_23");
        speedLine3.x=-138;speedLine3.y=978;
        TweenMax.to(speedLine3,1,{delay:0.6,x:402,y:321,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine4=PSP("page2_24");
        speedLine4.x=-54;speedLine4.y=837;
        TweenMax.to(speedLine4,1,{x:380,y:315,repeat:-1,alpha:0.0,ease:Cubic.easeOut});

        var mask1=new PIXI.Graphics();
        mask1.beginFill(0x000000,1);
        mask1.drawRect(0,0,740,540);
        mask1.y=535;

        var mask2=new PIXI.Graphics();
        mask2.beginFill(0x000000,1);
        mask2.drawRect(0,0,740,540);
        mask2.y=535;

        var mask3=new PIXI.Graphics();
        mask3.beginFill(0x000000,1);
        mask3.drawRect(0,0,740,540);
        mask3.y=535;

        var mask4=new PIXI.Graphics();
        mask4.beginFill(0x000000,1);
        mask4.drawRect(0,0,740,540);
        mask4.y=535;

        var speedLine5=PSP("page2_25");
        speedLine5.x=740;speedLine5.y=1002;
        TweenMax.to(speedLine5,1,{x:247,y:372,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine6=PSP("page2_26");
        speedLine6.x=740;speedLine6.y=1002;
        TweenMax.to(speedLine6,1,{delay:0.15,x:309,y:456,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine7=PSP("page2_27");
        speedLine7.x=724;speedLine7.y=1003;
        TweenMax.to(speedLine7,1,{delay:0.45,x:257,y:392,repeat:-1,alpha:0.0,ease:Cubic.easeOut});
        var speedLine8=PSP("page2_28");
        speedLine8.x=729;speedLine8.y=946;
        TweenMax.to(speedLine8,1,{delay:0.5,x:187,y:277,repeat:-1,alpha:0.0,ease:Cubic.easeOut});

        var mask5=new PIXI.Graphics();
        mask5.beginFill(0x000000,1);
        mask5.drawRect(0,0,740,540);
        mask5.y=535;

        var mask6=new PIXI.Graphics();
        mask6.beginFill(0x000000,1);
        mask6.drawRect(0,0,740,540);
        mask6.y=535;

        var mask7=new PIXI.Graphics();
        mask7.beginFill(0x000000,1);
        mask7.drawRect(0,0,740,540);
        mask7.y=535;

        var mask8=new PIXI.Graphics();
        mask8.beginFill(0x000000,1);
        mask8.drawRect(0,0,740,540);
        mask8.y=535;

        speedLine1.mask=mask1;
        speedLine2.mask=mask2;
        speedLine3.mask=mask3;
        speedLine4.mask=mask4;
        speedLine5.mask=mask5;
        speedLine6.mask=mask6;
        speedLine7.mask=mask7;
        speedLine8.mask=mask8;

        //**********************
        //**********************
        //**********************
        //**********************

        // whole.addChild(bg);
        whole.addChild(bgUp);
        whole.addChild(bgUp2);
        whole.addChild(bgUp3);
        whole.addChild(bgDown);
        whole.addChild(pink);
        whole.addChild(title1);
        whole.addChild(word1);
        whole.addChild(word2);
        whole.addChild(line1);
        whole.addChild(line2);
        whole.addChild(title2);
        whole.addChild(title3);

        //**********************
        //**********************
        //**********************
        //**********************
        whole.addChild(speedLine1);
        whole.addChild(speedLine2);
        whole.addChild(speedLine3);
        whole.addChild(speedLine4);
        whole.addChild(speedLine5);
        whole.addChild(speedLine6);
        whole.addChild(speedLine7);
        whole.addChild(speedLine8);

        whole.addChild(mask1);
        whole.addChild(mask2);
        whole.addChild(mask3);
        whole.addChild(mask4);
        whole.addChild(mask5);
        whole.addChild(mask6);
        whole.addChild(mask7);
        whole.addChild(mask8);

        //**********************
        //**********************
        //**********************
        //**********************

        bigWhole.addChild(whole);
        // bigWhole.addChild(wordBG);
        // bigWhole.addChild(word);


        bigWhole.addChild(sir);
        bigWhole.addChild(sir2);
        bigWhole.addChild(sir3);
        bigWhole.addChild(bottom1);
        bigWhole.addChild(bottom2);

        bigWhole.addChild(wholeMask);




        bg.x=0;bg.y=0;
        pink.x=0;pink.y=0;
        title1.x=20;title1.y=32;
        title2.x=27;title2.y=32;
        title3.x=38;title3.y=32;
        wordBG.x=0;wordBG.y=410;
        word.x=35;word.y=446;
        sir.x=301;sir.y=680;
        bottom1.x=241;bottom1.y=959;
        bottom2.x=280;bottom2.y=1017;

        word1.x=304;word1.y=325;
        word2.x=200;word2.y=376;



        pink.blendMode=PIXI.BLEND_MODES.MULTIPLY;

        bg.alpha=0;
        pink.alpha=1;
        title1.alpha=0;
        title2.alpha=0;
        title3.alpha=0;
        wordBG.alpha=0;
        word.alpha=0;
        bottom1.alpha=0;
        bottom2.alpha=0;
        word1.alpha=0;
        word2.alpha=0;
        line1.alpha=0;
        line2.alpha=0;

        bgUp2.alpha=0;
        bgUp3.alpha=0;

        // sir.anchor.set(0.5);
        // TweenMax.to(sir.skew,2,{delay:0.5,x:0.5,y:1});
        // TweenMax.to(sir,2,{delay:0.5,rotation:Math.PI/180*30});

        // sir.skew.x=0.5;
        // sir.skew.x=0.5;

        //第二页
        sir2.skew.set(0.57,1);
        sir2.rotation = Math.PI / 180 * 30;
        sir2.x=309+sir2.width/2;sir2.y=630+sir2.height/2;
        sir2.anchor.set(0.5);


        sir3.skew.set(0.57,1);
        sir3.rotation = Math.PI / 180 * 30;
        sir3.x=313+sir3.width/2;sir3.y=631+sir3.height/2;
        sir3.anchor.set(0.5);


        var sirIdx=1;
        var clickSirSp=new PIXI.Graphics();
        clickSirSp.beginFill(0xff0000,0);
        clickSirSp.drawRect(0,0,150,300);
        clickSirSp.x=300;clickSirSp.y=700;
        whole.addChild(clickSirSp);
        whole.on("pointerdown",changePage)

        var arr_sirPiece=[];
        sirPiece();
        function sirPiece(){
            for(var i=0;i<12;i++){
                for(var j=0;j<34;j++){
                    var texture=PSP("page2_16").texture.clone();
                    var square=new PIXI.Rectangle(i*10,j*10,10,10);
                    texture.frame=square;
                    var piece=new PIXI.Sprite(texture);
                    piece.x=313+i*10;piece.y=631+j*10;
                    piece.alpha=0;
                    whole.addChild(piece);
                    arr_sirPiece.push(piece);
                }
            }
        }

        function sirSplit(){
            for(var z=0;z<arr_sirPiece.length;z++){
                var xx=arr_sirPiece[z].x-Math.random()*400+200;
                var yy=arr_sirPiece[z].y-Math.random()*400+200;
                TweenMax.to(arr_sirPiece[z],0.01,{alpha:1});
                TweenMax.to(arr_sirPiece[z],0.7+Math.random()*1,{delay:0.01,alpha:0,x:xx,y:yy,ease:Cubic.easeInOut});
            }
        }

        //开始
        page.start=function() {

            TweenMax.to(bgUp.scale,40,{delay:4,yoyo:true,repeat:-1,x:2,y:2});

            setTimeout(function(){
                whole.interactive=true;
            },3500+delayTime*1000);

            sir.skew.set(0.57, 1);
            sir.rotation = Math.PI / 180 * 30;
            sir.x += 129 / 2;
            sir.y += 266 / 2;


            sir.anchor.set(0.5);
            TweenMax.to(sir.skew, 0.5, {delay: 0.5 + delayTime, x: 0, y: 0, ease: Cubic.easeOut});
            TweenMax.to(sir, 0.5, {delay: 0.5 + delayTime, rotation: 0, ease: Cubic.easeOut});


            word.y -= 30;
            TweenMax.to(wordBG, 0.7, {delay: 0.5 + delayTime, alpha: 1, ease: Cubic.easeOut});
            TweenMax.to(word, 0.7, {delay: 0.7 + delayTime, alpha: 1, y: word.y + 30, ease: Cubic.easeOut});


            wholeMask.x = -200;
            wholeMask.y = 1136 / 2 + 50;
            whole.mask = wholeMask;
            TweenMax.to(wholeMask.scale, 1, {delay: 1.05 + delayTime, y: 1, ease: Cubic.easeOut});
            TweenMax.to(wholeMask, 1, {delay: 1.05 + delayTime, x: 0, y: 0, rotation: 0, ease: Cubic.easeOut});

            word1.y+=20;word2.y-=20;
            TweenMax.to(word1,0.7,{delay:2.5+delayTime,alpha:1,y:word1.y-20,ease:Cubic.easeOut});
            TweenMax.to(word2,0.7,{delay:2.5+delayTime,alpha:1,y:word2.y+20,ease:Cubic.easeOut});

            line1.x-=20;line2.x+=20;
            TweenMax.to(line1,0.7,{delay:2.2+delayTime,alpha:1,x:line1.x+20,ease:Cubic.easeOut});
            TweenMax.to(line2,0.7,{delay:2.2+delayTime,alpha:1,x:line2.x-20,ease:Cubic.easeOut});


            title1.anchor.set(0.5);
            title1.x = 20 + 702 / 2;
            title1.y = 400;
            title1.scale.set(3);
            TweenMax.to(title1, 1, {
                delay: 1.6 + delayTime,
                alpha: 1,
                x: 20 + 702 / 2,
                y: 32 + 83 / 2,
                ease: Cubic.easeOut
            });
            TweenMax.to(title1.scale, 1, {delay: 1.6 + delayTime, x: 1, y: 1, ease: Cubic.easeInOut});


            bottom1.x += 50;
            bottom2.y += 50;
            TweenMax.to(bottom1, 0.7, {delay: 2.8 + delayTime, alpha: 1, x: bottom1.x - 50, ease: Cubic.easeOut});
            TweenMax.to(bottom2, 0.7, {delay: 3 + delayTime, alpha: 1, y: bottom2.y - 50, ease: Cubic.easeOut});
        }


        function changePage(){
            sirIdx++;
            switch(sirIdx){
                case 2:
                    TweenMax.to(bgUp,1,{alpha:0,ease:Cubic.easeOut});
                    TweenMax.to(bgUp2,1,{alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(bgUp2.scale,40,{yoyo:true,repeat:-1,x:1.2,y:1.2});


                    TweenMax.to(sir.skew, 0.5, {x: -0.57, y: -1, ease: Cubic.easeOut});
                    TweenMax.to(sir, 0.5, { rotation: Math.PI/180*-30, ease: Cubic.easeOut});

                    TweenMax.to(sir2.skew, 0.5, {delay: 0.5, x: 0, y: 0, ease: Cubic.easeOut});
                    TweenMax.to(sir2, 0.5, {delay: 0.5, rotation: 0, ease: Cubic.easeOut});
                    whole.interactive=false;
                    setTimeout(function(){
                        whole.interactive=true;
                    },2500);

                    TweenMax.to(line1,0.5,{x:line1.x+30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(line2,0.5,{x:line1.x-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word1,0.5,{delay:0.2,y:word1.y-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word2,0.5,{delay:0.2,y:word2.y+30,alpha:0,ease:Cubic.easeIn});

                    setTimeout(function(){
                        word1.texture=PSP("page2_18").texture;
                        word2.texture=PSP("page2_19").texture;
                        word1.x=217;
                        word2.x=200;
                    },800);


                    TweenMax.to(line1,0.01,{delay:0.8,x:-20});
                    TweenMax.to(line2,0.01,{delay:0.8,x:20});
                    TweenMax.to(word1,0.01,{delay:0.8,y:325+20});
                    TweenMax.to(word2,0.01,{delay:0.8,y:375-20});

                    TweenMax.to(line1,0.7,{delay:0.81,x:0,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(line2,0.7,{delay:0.81,x:0,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(word1,0.7,{delay:0.81,y:325,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(word2,0.7,{delay:0.81,y:375,alpha:1,ease:Cubic.easeOut});

                    TweenMax.to(title1,0.7,{y:-50,alpha:0,ease:Cubic.easeOut});
                    title2.anchor.set(0.5);
                    title2.x = 20 + 708 / 2;
                    title2.y =400;
                    title2.scale.set(3);
                    TweenMax.to(title2, 1, {delay: 1 , alpha: 1, x: 20 + 702 / 2, y: 32 + 87 / 2, ease: Cubic.easeOut});
                    TweenMax.to(title2.scale, 1, {delay: 1 , x: 1, y: 1, ease: Cubic.easeInOut});

                    break;
                case 3:
                    TweenMax.to(bgUp2,1,{alpha:0,ease:Cubic.easeOut});
                    TweenMax.to(bgUp3,1,{alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(bgUp3.scale,40,{yoyo:true,repeat:-1,x:1.2,y:1.2});


                    TweenMax.to(sir2.skew, 0.5, {x: -0.57, y: -1, ease: Cubic.easeOut});
                    TweenMax.to(sir2, 0.5, { rotation: Math.PI/180*-30, ease: Cubic.easeOut});

                    TweenMax.to(sir3.skew, 0.5, {delay: 0.5, x: 0, y: 0, ease: Cubic.easeOut});
                    TweenMax.to(sir3, 0.5, {delay: 0.5, rotation: 0, ease: Cubic.easeOut});
                    whole.interactive=false;
                    setTimeout(function(){
                        whole.interactive=true;
                    },2500);

                    TweenMax.to(line1,0.5,{x:line1.x+30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(line2,0.5,{x:line1.x-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word1,0.5,{delay:0.2,y:word1.y-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word2,0.5,{delay:0.2,y:word2.y+30,alpha:0,ease:Cubic.easeIn});

                    setTimeout(function(){
                        word1.texture=PSP("page2_30").texture;
                        word2.texture=PSP("page2_31").texture;
                        word1.x=271;
                        word2.x=136;
                    },800);


                    TweenMax.to(line1,0.01,{delay:0.8,x:-20});
                    TweenMax.to(line2,0.01,{delay:0.8,x:20});
                    TweenMax.to(word1,0.01,{delay:0.8,y:325+20});
                    TweenMax.to(word2,0.01,{delay:0.8,y:375-20});

                    TweenMax.to(line1,0.7,{delay:0.81,x:0,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(line2,0.7,{delay:0.81,x:0,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(word1,0.7,{delay:0.81,y:325,alpha:1,ease:Cubic.easeOut});
                    TweenMax.to(word2,0.7,{delay:0.81,y:375,alpha:1,ease:Cubic.easeOut});

                    TweenMax.to(title2,0.7,{y:-50,alpha:0,ease:Cubic.easeOut});
                    title3.anchor.set(0.5);
                    title3.x = 38 + 670 / 2;
                    title3.y =400;
                    title3.scale.set(3);
                    TweenMax.to(title3, 1, {delay: 1 , alpha: 1, x: 38 + 702 / 2, y: 25 + 100 / 2, ease: Cubic.easeOut});
                    TweenMax.to(title3.scale, 1, {delay: 1 , x: 1, y: 1, ease: Cubic.easeInOut});

                    break;
                case 4:
                    whole.interactive=false;
                    TweenMax.to(line1,0.5,{x:line1.x+30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(line2,0.5,{x:line1.x-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word1,0.5,{delay:0.2,y:word1.y-30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(word2,0.5,{delay:0.2,y:word2.y+30,alpha:0,ease:Cubic.easeIn});
                    TweenMax.to(title3,0.7,{y:-50,alpha:0,ease:Cubic.easeOut});

                    TweenMax.killTweensOf(speedLine1);
                    TweenMax.killTweensOf(speedLine2);
                    TweenMax.killTweensOf(speedLine3);
                    TweenMax.killTweensOf(speedLine4);
                    TweenMax.killTweensOf(speedLine5);
                    TweenMax.killTweensOf(speedLine6);
                    TweenMax.killTweensOf(speedLine7);
                    TweenMax.killTweensOf(speedLine8);
                    speedLine1.alpha=0;
                    speedLine2.alpha=0;
                    speedLine3.alpha=0;
                    speedLine4.alpha=0;
                    speedLine5.alpha=0;
                    speedLine6.alpha=0;
                    speedLine7.alpha=0;
                    speedLine8.alpha=0;

                    TweenMax.to(bottom1,0.5,{alpha:0});
                    TweenMax.to(bottom2,0.5,{alpha:0});
                    TweenMax.to(pink,0.5,{delay:0.7,y:-1136,alpha:0});
                    // TweenMax.to(bg,0.5,{delay:0.7,alpha:0});
                    TweenMax.killTweensOf(bgUp);
                    TweenMax.killTweensOf(bgUp2);
                    TweenMax.killTweensOf(bgUp3);
                    TweenMax.to(bgUp3,0.5,{delay:0.7,alpha:0});
                    TweenMax.to(bgDown,0.5,{delay:0.7,alpha:0});

                    TweenMax.to(sir3,0.1,{delay:1.1,alpha:0});

                    setTimeout(function(){
                        sirSplit();
                        document.dispatchEvent(new CustomEvent("PageChange",{detail:3}));
                    },1100)

                    break;
            }
        }
        page.End=function(){

        }

        page.In=function(){

        }
        page.Out=function(){

        }
        page.ReturnWhole=function(){
            return bigWhole;
        }
        return page;
    }
}
